<?php

namespace common\models;

use Yii;

class GoodsCate extends \common\components\ARModel
{
    const STATE_YES = 0;
    const STATE_NO = 1;

    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'unique'],
            [['state', 'hot'], 'integer'],
            [['hot'], 'integer', 'max' => 255]
        ];
    }

    public function attributeLabels()
    {
        return [
            'id' => '分类ID',
            'name' => '分类名称',
            'state' => '分类状态',
            'hot' => '分类排序',
        ];
    }

    /****************************** 以下为公共显示条件的方法 ******************************/

    public function search()
    {
        $this->setSearchParams();

        return self::find()
            ->filterWhere([
                'goodsCate.name' => $this->name,
                'goodsCate.state' => $this->state
            ])
            ->andTableSearch()
            ;
    }

    /****************************** 以下为字段的映射方法和格式化方法 ******************************/
    // Map method of field `state`
    public static function getStateMap($prepend = false)
    {
        $map = [
            self::STATE_YES => '开启',
            self::STATE_NO => '关闭',
        ];

        return self::resetMap($map, $prepend);
    }

    // Format method of field `state`
    public function getStateValue($value = null)
    {
        return $this->resetValue($value);
    }
}